package com.zmm.myyimixian.ui.activity.main.home;

import android.os.Handler;
import android.os.Message;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.zmm.myyimixian.bean.HomeGoods;
import com.zmm.myyimixian.config.ConfigPath;
import com.zmm.myyimixian.http.OkHttpClientUtils;

import java.io.IOException;
import java.lang.reflect.Type;

/**
 * Created by wencai2015 on 2016/10/21.
 */

public class MyListViewActivityThread extends Thread {
    private Handler handler;
    private String bh;
    public MyListViewActivityThread(Handler handler, String bh){
        this.handler = handler;
        this.bh = bh;
    }
    @Override
    public void run() {
        try {
            String fromUrl = OkHttpClientUtils.getStringFromUrl(ConfigPath.getListActivity(bh));
            Gson gson = new Gson();
            Type type = new TypeToken<HomeGoods>(){}.getType();
            HomeGoods homeGoods = gson.fromJson(fromUrl, type);
            Message msg = Message.obtain();
            msg.what = 1;
            msg.obj = homeGoods;
            handler.sendMessage(msg);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
